package org.lee.springcloud.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import reactor.core.publisher.Mono;

/**
 * @author jackielee
 * @version 1.0
 * @description GatewayHystryApplication
 * @date 2021/3/25
 */
@SpringBootApplication
public class GatewayHystryApplication {
  public static void main(String[] args) {
    SpringApplication.run(GatewayHystryApplication.class, args);
  }

  /**
   * 配置RequestRateLimiter的keyResolver
   * @return
   */
  @Bean
  KeyResolver userKeyResolver() {
    return exchange -> Mono.just((exchange.getRequest().getQueryParams().getFirst("user"))); // 通过请求参数中的user进行限流
  }
}
